Optimal. Leaf size=59 \[ \frac {a x}{b^2}-\frac {2 \sqrt {a-b} \sqrt {a+b} \text {ArcTan}\left (\frac {\sqrt {a-b} \tan \left (\frac {x}{2}\right )}{\sqrt {a+b}}\right )}{b^2}-\frac {\sin (x)}{b} \]
[Out]
________________________________________________________________________________________
Rubi [A]
time = 0.07, antiderivative size = 59, normalized size of antiderivative = 1.00, number of steps
used = 4, number of rules used = 4, integrand size = 13, \(\frac {\text {number of rules}}{\text {integrand size}}\) = 0.308, Rules used = {2774, 2814,
2738, 211} \begin {gather*} -\frac {2 \sqrt {a-b} \sqrt {a+b} \text {ArcTan}\left (\frac {\sqrt {a-b} \tan \left (\frac {x}{2}\right )}{\sqrt {a+b}}\right )}{b^2}+\frac {a x}{b^2}-\frac {\sin (x)}{b} \end {gather*}
Antiderivative was successfully verified.
[In]
[Out]
Rule 211
Rule 2738
Rule 2774
Rule 2814
Rubi steps
\begin {align*} \int \frac {\sin ^2(x)}{a+b \cos (x)} \, dx &=-\frac {\sin (x)}{b}-\frac {\int \frac {-b-a \cos (x)}{a+b \cos (x)} \, dx}{b}\\ &=\frac {a x}{b^2}-\frac {\sin (x)}{b}+\left (1-\frac {a^2}{b^2}\right ) \int \frac {1}{a+b \cos (x)} \, dx\\ &=\frac {a x}{b^2}-\frac {\sin (x)}{b}+\left (2 \left (1-\frac {a^2}{b^2}\right )\right ) \text {Subst}\left (\int \frac {1}{a+b+(a-b) x^2} \, dx,x,\tan \left (\frac {x}{2}\right )\right )\\ &=\frac {a x}{b^2}-\frac {2 \sqrt {a-b} \sqrt {a+b} \tan ^{-1}\left (\frac {\sqrt {a-b} \tan \left (\frac {x}{2}\right )}{\sqrt {a+b}}\right )}{b^2}-\frac {\sin (x)}{b}\\ \end {align*}
________________________________________________________________________________________
Mathematica [A]
time = 0.08, size = 54, normalized size = 0.92 \begin {gather*} \frac {a x-2 \sqrt {-a^2+b^2} \tanh ^{-1}\left (\frac {(a-b) \tan \left (\frac {x}{2}\right )}{\sqrt {-a^2+b^2}}\right )-b \sin (x)}{b^2} \end {gather*}
Antiderivative was successfully verified.
[In]
[Out]
________________________________________________________________________________________
Maple [A]
time = 0.11, size = 78, normalized size = 1.32
method | result | size |
default | \(\frac {-\frac {2 b \tan \left (\frac {x}{2}\right )}{\tan ^{2}\left (\frac {x}{2}\right )+1}+2 a \arctan \left (\tan \left (\frac {x}{2}\right )\right )}{b^{2}}-\frac {2 \left (a +b \right ) \left (a -b \right ) \arctan \left (\frac {\left (a -b \right ) \tan \left (\frac {x}{2}\right )}{\sqrt {\left (a -b \right ) \left (a +b \right )}}\right )}{b^{2} \sqrt {\left (a -b \right ) \left (a +b \right )}}\) | \(78\) |
risch | \(\frac {a x}{b^{2}}+\frac {i {\mathrm e}^{i x}}{2 b}-\frac {i {\mathrm e}^{-i x}}{2 b}-\frac {\sqrt {-a^{2}+b^{2}}\, \ln \left ({\mathrm e}^{i x}-\frac {i \sqrt {-a^{2}+b^{2}}-a}{b}\right )}{b^{2}}+\frac {\sqrt {-a^{2}+b^{2}}\, \ln \left ({\mathrm e}^{i x}+\frac {i \sqrt {-a^{2}+b^{2}}+a}{b}\right )}{b^{2}}\) | \(118\) |
Verification of antiderivative is not currently implemented for this CAS.
[In]
[Out]
________________________________________________________________________________________
Maxima [F(-2)]
time = 0.00, size = 0, normalized size = 0.00 \begin {gather*} \text {Exception raised: ValueError} \end {gather*}
Verification of antiderivative is not currently implemented for this CAS.
[In]
[Out]
________________________________________________________________________________________
Fricas [A]
time = 0.41, size = 154, normalized size = 2.61 \begin {gather*} \left [\frac {2 \, a x - 2 \, b \sin \left (x\right ) + \sqrt {-a^{2} + b^{2}} \log \left (\frac {2 \, a b \cos \left (x\right ) + {\left (2 \, a^{2} - b^{2}\right )} \cos \left (x\right )^{2} + 2 \, \sqrt {-a^{2} + b^{2}} {\left (a \cos \left (x\right ) + b\right )} \sin \left (x\right ) - a^{2} + 2 \, b^{2}}{b^{2} \cos \left (x\right )^{2} + 2 \, a b \cos \left (x\right ) + a^{2}}\right )}{2 \, b^{2}}, \frac {a x - b \sin \left (x\right ) - \sqrt {a^{2} - b^{2}} \arctan \left (-\frac {a \cos \left (x\right ) + b}{\sqrt {a^{2} - b^{2}} \sin \left (x\right )}\right )}{b^{2}}\right ] \end {gather*}
Verification of antiderivative is not currently implemented for this CAS.
[In]
[Out]
________________________________________________________________________________________
Sympy [B] Leaf count of result is larger than twice the leaf count of optimal. 991 vs.
\(2 (49) = 98\).
time = 53.72, size = 991, normalized size = 16.80 \begin {gather*} \begin {cases} \tilde {\infty } \left (- \frac {\log {\left (\tan {\left (\frac {x}{2} \right )} - 1 \right )} \tan ^{2}{\left (\frac {x}{2} \right )}}{\tan ^{2}{\left (\frac {x}{2} \right )} + 1} - \frac {\log {\left (\tan {\left (\frac {x}{2} \right )} - 1 \right )}}{\tan ^{2}{\left (\frac {x}{2} \right )} + 1} + \frac {\log {\left (\tan {\left (\frac {x}{2} \right )} + 1 \right )} \tan ^{2}{\left (\frac {x}{2} \right )}}{\tan ^{2}{\left (\frac {x}{2} \right )} + 1} + \frac {\log {\left (\tan {\left (\frac {x}{2} \right )} + 1 \right )}}{\tan ^{2}{\left (\frac {x}{2} \right )} + 1} - \frac {2 \tan {\left (\frac {x}{2} \right )}}{\tan ^{2}{\left (\frac {x}{2} \right )} + 1}\right ) & \text {for}\: a = 0 \wedge b = 0 \\\frac {x \tan ^{2}{\left (\frac {x}{2} \right )}}{b \tan ^{2}{\left (\frac {x}{2} \right )} + b} + \frac {x}{b \tan ^{2}{\left (\frac {x}{2} \right )} + b} - \frac {2 \tan {\left (\frac {x}{2} \right )}}{b \tan ^{2}{\left (\frac {x}{2} \right )} + b} & \text {for}\: a = b \\- \frac {x \tan ^{2}{\left (\frac {x}{2} \right )}}{b \tan ^{2}{\left (\frac {x}{2} \right )} + b} - \frac {x}{b \tan ^{2}{\left (\frac {x}{2} \right )} + b} - \frac {2 \tan {\left (\frac {x}{2} \right )}}{b \tan ^{2}{\left (\frac {x}{2} \right )} + b} & \text {for}\: a = - b \\\frac {\frac {x \sin ^{2}{\left (x \right )}}{2} + \frac {x \cos ^{2}{\left (x \right )}}{2} - \frac {\sin {\left (x \right )} \cos {\left (x \right )}}{2}}{a} & \text {for}\: b = 0 \\\frac {a x \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}} \tan ^{2}{\left (\frac {x}{2} \right )}}{b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}} \tan ^{2}{\left (\frac {x}{2} \right )} + b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}}} + \frac {a x \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}}}{b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}} \tan ^{2}{\left (\frac {x}{2} \right )} + b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}}} - \frac {a \log {\left (- \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}} + \tan {\left (\frac {x}{2} \right )} \right )} \tan ^{2}{\left (\frac {x}{2} \right )}}{b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}} \tan ^{2}{\left (\frac {x}{2} \right )} + b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}}} - \frac {a \log {\left (- \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}} + \tan {\left (\frac {x}{2} \right )} \right )}}{b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}} \tan ^{2}{\left (\frac {x}{2} \right )} + b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}}} + \frac {a \log {\left (\sqrt {- \frac {a}{a - b} - \frac {b}{a - b}} + \tan {\left (\frac {x}{2} \right )} \right )} \tan ^{2}{\left (\frac {x}{2} \right )}}{b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}} \tan ^{2}{\left (\frac {x}{2} \right )} + b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}}} + \frac {a \log {\left (\sqrt {- \frac {a}{a - b} - \frac {b}{a - b}} + \tan {\left (\frac {x}{2} \right )} \right )}}{b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}} \tan ^{2}{\left (\frac {x}{2} \right )} + b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}}} - \frac {2 b \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}} \tan {\left (\frac {x}{2} \right )}}{b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}} \tan ^{2}{\left (\frac {x}{2} \right )} + b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}}} - \frac {b \log {\left (- \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}} + \tan {\left (\frac {x}{2} \right )} \right )} \tan ^{2}{\left (\frac {x}{2} \right )}}{b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}} \tan ^{2}{\left (\frac {x}{2} \right )} + b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}}} - \frac {b \log {\left (- \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}} + \tan {\left (\frac {x}{2} \right )} \right )}}{b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}} \tan ^{2}{\left (\frac {x}{2} \right )} + b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}}} + \frac {b \log {\left (\sqrt {- \frac {a}{a - b} - \frac {b}{a - b}} + \tan {\left (\frac {x}{2} \right )} \right )} \tan ^{2}{\left (\frac {x}{2} \right )}}{b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}} \tan ^{2}{\left (\frac {x}{2} \right )} + b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}}} + \frac {b \log {\left (\sqrt {- \frac {a}{a - b} - \frac {b}{a - b}} + \tan {\left (\frac {x}{2} \right )} \right )}}{b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}} \tan ^{2}{\left (\frac {x}{2} \right )} + b^{2} \sqrt {- \frac {a}{a - b} - \frac {b}{a - b}}} & \text {otherwise} \end {cases} \end {gather*}
Verification of antiderivative is not currently implemented for this CAS.
[In]
[Out]
________________________________________________________________________________________
Giac [A]
time = 0.45, size = 90, normalized size = 1.53 \begin {gather*} \frac {a x}{b^{2}} + \frac {2 \, {\left (\pi \left \lfloor \frac {x}{2 \, \pi } + \frac {1}{2} \right \rfloor \mathrm {sgn}\left (-2 \, a + 2 \, b\right ) + \arctan \left (-\frac {a \tan \left (\frac {1}{2} \, x\right ) - b \tan \left (\frac {1}{2} \, x\right )}{\sqrt {a^{2} - b^{2}}}\right )\right )} \sqrt {a^{2} - b^{2}}}{b^{2}} - \frac {2 \, \tan \left (\frac {1}{2} \, x\right )}{{\left (\tan \left (\frac {1}{2} \, x\right )^{2} + 1\right )} b} \end {gather*}
Verification of antiderivative is not currently implemented for this CAS.
[In]
[Out]
________________________________________________________________________________________
Mupad [B]
time = 0.49, size = 74, normalized size = 1.25 \begin {gather*} \frac {2\,\mathrm {atanh}\left (\frac {\sin \left (\frac {x}{2}\right )\,\sqrt {b^2-a^2}}{a\,\cos \left (\frac {x}{2}\right )+b\,\cos \left (\frac {x}{2}\right )}\right )\,\sqrt {b^2-a^2}}{b^2}-\frac {\sin \left (x\right )}{b}+\frac {2\,a\,\mathrm {atan}\left (\frac {\sin \left (\frac {x}{2}\right )}{\cos \left (\frac {x}{2}\right )}\right )}{b^2} \end {gather*}
Verification of antiderivative is not currently implemented for this CAS.
[In]
[Out]
________________________________________________________________________________________